home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / geowindo / samplevi.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-08  |  10.3 KB  |  383 lines

  1. // SampleView.cpp : implementation of the CSampleView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Sample.h"
  6.  
  7. #include "SampleDoc.h"
  8. #include "SampleView.h"
  9. #include "GeometryManager.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CSampleView
  19.  
  20. IMPLEMENT_DYNCREATE(CSampleView, CFormView)
  21.  
  22. BEGIN_MESSAGE_MAP(CSampleView, CFormView)
  23.     //{{AFX_MSG_MAP(CSampleView)
  24.     ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
  25.     ON_NOTIFY(TCN_SELCHANGING, IDC_TAB, OnSelchangingTab)
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CSampleView construction/destruction
  31.  
  32. CSampleView::CSampleView()
  33.     : CFormView(CSampleView::IDD)
  34. {
  35.     //{{AFX_DATA_INIT(CSampleView)
  36.         // NOTE: the ClassWizard will add member initialization here
  37.     //}}AFX_DATA_INIT
  38.     // TODO: add construction code here
  39.  
  40. }
  41.  
  42. CSampleView::~CSampleView()
  43. {
  44. }
  45.  
  46. void CSampleView::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CFormView::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CSampleView)
  50.     DDX_Control(pDX, IDC_TAB, m_TabCtrl);
  51.     //}}AFX_DATA_MAP
  52. }
  53.  
  54. BOOL CSampleView::PreCreateWindow(CREATESTRUCT& cs)
  55. {
  56.     // TODO: Modify the Window class or styles here by modifying
  57.     //  the CREATESTRUCT cs
  58.  
  59.     return CFormView::PreCreateWindow(cs);
  60. }
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CSampleView diagnostics
  64.  
  65. #ifdef _DEBUG
  66. void CSampleView::AssertValid() const
  67. {
  68.     CFormView::AssertValid();
  69. }
  70.  
  71. void CSampleView::Dump(CDumpContext& dc) const
  72. {
  73.     CFormView::Dump(dc);
  74. }
  75.  
  76. CSampleDoc* CSampleView::GetDocument() // non-debug version is inline
  77. {
  78.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSampleDoc)));
  79.     return (CSampleDoc*)m_pDocument;
  80. }
  81. #endif //_DEBUG
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CSampleView message handlers
  85.  
  86. void CSampleView::OnInitialUpdate() 
  87. {
  88.     CFormView::OnInitialUpdate();
  89.     
  90.     // we don't want any scroll bars
  91.     SetScrollSizes(MM_TEXT, CSize(0, 0));
  92.  
  93.     // create the tab pages
  94.     m_TabPage1.Create(IDD_TAB_PAGE1, &m_TabCtrl);
  95.     m_TabPage2.Create(IDD_TAB_PAGE2, &m_TabCtrl);
  96.     m_TabPage3.Create(IDD_TAB_PAGE3, &m_TabCtrl);
  97.  
  98.     TC_ITEM tcItem = {0};
  99.     tcItem.mask = TCIF_TEXT;
  100.     tcItem.pszText = "Page 1";
  101.     m_TabCtrl.InsertItem(0, &tcItem);
  102.     tcItem.pszText = "Page 2";
  103.     m_TabCtrl.InsertItem(1, &tcItem);
  104.     tcItem.pszText = "Page 3";
  105.     m_TabCtrl.InsertItem(2, &tcItem);
  106.  
  107.     m_TabPage1.ShowWindow(SW_SHOW);
  108.  
  109.     // initialize the geometry manager
  110.     //
  111.     // the default behavior is fine
  112.     //
  113.     HGEOM hGeom = GmStartDefinition(0);
  114.     ASSERT(hGeom);
  115.     if (!hGeom)
  116.         return;
  117.     
  118.     // add the top-level frame window group
  119.     //
  120.     // arrange its direct children vertically
  121.     //
  122.     // Notice that since this window are a CFormView, you need to
  123.     // pass in the window handle of the parent frame window.
  124.     //
  125.     HGMGROUP hTopFrame = GmAddTopFrameWnd(hGeom, GetParentFrame()->m_hWnd, GM_VERTICAL);
  126.     if (hTopFrame)
  127.     {
  128.         // add the generic group for the static text and edit field
  129.         //
  130.         // arrange its direct children horizontally
  131.         // give it a weight of 0
  132.         //
  133.         HGMGROUP hGroup1 = GmAddGroup(hGeom, hTopFrame, GM_HORIZONTAL, 0);
  134.         if (hGroup1)
  135.         {
  136.             // add the static text group
  137.             //
  138.             // left-align and vertically center it
  139.             // give it a weight of 0
  140.             //
  141.             GmAddWnd(hGeom, hGroup1, ::GetDlgItem(m_hWnd, IDC_NAME_LABEL), GM_LEFT | GM_VCENTER, 0);
  142.             
  143.             // add the edit field group
  144.             //
  145.             // allow it to grow horizontally
  146.             // give it a weight of 1
  147.             //
  148.             GmAddWnd(hGeom, hGroup1, ::GetDlgItem(m_hWnd, IDC_NAME), GM_GROW_X, 1);
  149.         }
  150.             
  151.         // add the generic group for the rest of the controls
  152.         //
  153.         // arrange its direct children horizontally
  154.         // give it a weight of 1
  155.         //
  156.         hGroup1 = GmAddGroup(hGeom, hTopFrame, GM_HORIZONTAL, 1);
  157.         if (hGroup1)
  158.         {
  159.             // add the generic group for the controls on the left
  160.             //
  161.             // arrange its direct children vertically
  162.             // give it a weight of 3
  163.             //
  164.             HGMGROUP hGroup2 = GmAddGroup(hGeom, hGroup1, GM_VERTICAL, 3);
  165.             if (hGroup2)
  166.             {
  167.                 // add the generic group for the static text and edit field
  168.                 //
  169.                 // arrange its direct children vertically
  170.                 // give it a weight of 1
  171.                 //
  172.                 HGMGROUP hGroup3 = GmAddGroup(hGeom, hGroup2, GM_VERTICAL, 1);
  173.                 if (hGroup3)
  174.                 {
  175.                     // add the static text group
  176.                     //
  177.                     // left-align and vertically center it
  178.                     // give it a weight of 0
  179.                     //
  180.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_ADDRESS_LABEL), GM_LEFT | GM_VCENTER, 0);
  181.                     
  182.                     // add the multiline edit field group
  183.                     //
  184.                     // allow it to grow (in both directions)
  185.                     // give it a weight of 1
  186.                     //
  187.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_ADDRESS), GM_GROW, 1);
  188.                 }
  189.                 
  190.                 // add the group box group
  191.                 //
  192.                 // arrange its direct children vertically
  193.                 // horizontally center it
  194.                 // give it a weight of 0
  195.                 //
  196.                 hGroup3 = GmAddGroupBox(hGeom, hGroup2, ::GetDlgItem(m_hWnd, IDC_STUFF), GM_VERTICAL | GM_HCENTER, 0);
  197.                 if (hGroup3)
  198.                 {
  199.                     // add the radio button groups
  200.                     //
  201.                     // left-align and vertically center them
  202.                     // give them a weight of 0
  203.                     //
  204.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_STUFF_1), GM_LEFT | GM_VCENTER, 0);
  205.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_STUFF_2), GM_LEFT | GM_VCENTER, 0);
  206.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_STUFF_3), GM_LEFT | GM_VCENTER, 0);
  207.                 }
  208.             }
  209.             
  210.             // add the generic group for the controls on the right
  211.             //
  212.             // arrange its direct children vertically
  213.             // give it a weight of 1
  214.             //
  215.             hGroup2 = GmAddGroup(hGeom, hGroup1, GM_VERTICAL, 1);
  216.             if (hGroup2)
  217.             {
  218.                 // add the static text group
  219.                 //
  220.                 // left-align and vertically center it
  221.                 // give it a weight of 0
  222.                 //
  223.                 GmAddWnd(hGeom, hGroup2, ::GetDlgItem(m_hWnd, IDC_TAB_LABEL), GM_LEFT | GM_VCENTER, 0);
  224.                 
  225.                 // add the tab control group
  226.                 //
  227.                 // arrange its direct children overlapped
  228.                 // allow it to grow in both directions
  229.                 // give it a weight of 1
  230.                 //
  231.                 HGMGROUP hGroup3 = GmAddTabControl(hGeom, hGroup2, m_TabCtrl.m_hWnd, GM_GROW | GM_OVERLAPPED, 1);
  232.                 if (hGroup3)
  233.                 {
  234.                     // add the first tab page
  235.                     //
  236.                     // arrange its direct children horizontally
  237.                     // allow it to grow in both directions
  238.                     // give it a weight of 1
  239.                     //
  240.                     HGMGROUP hGroup4 = GmAddChildDialog(hGeom, hGroup3, m_TabPage1.m_hWnd, GM_GROW | GM_HORIZONTAL, 1);
  241.                     if (hGroup4)
  242.                     {
  243.                         // add the static text group
  244.                         //
  245.                         // left-align and vertically center it
  246.                         // give it a weight of 0
  247.                         //
  248.                         GmAddWnd(hGeom, hGroup4, ::GetDlgItem(m_TabPage1.m_hWnd, IDC_NAME_LABEL), GM_LEFT | GM_VCENTER, 0);
  249.                     
  250.                         // add the edit field group
  251.                         //
  252.                         // vertically center it
  253.                         // allow it to grow horizontally
  254.                         // give it a weight of 1
  255.                         //
  256.                         GmAddWnd(hGeom, hGroup4, ::GetDlgItem(m_TabPage1.m_hWnd, IDC_NAME), GM_GROW_X | GM_VCENTER, 1);
  257.                     }
  258.  
  259.                     // add the second tab page
  260.                     //
  261.                     // arrange its direct children vertically
  262.                     // allow it to grow in both directions
  263.                     // give it a weight of 1
  264.                     //
  265.                     hGroup4 = GmAddChildDialog(hGeom, hGroup3, m_TabPage2.m_hWnd, GM_GROW | GM_VERTICAL, 1);
  266.                     if (hGroup4)
  267.                     {
  268.                         // add the static text group
  269.                         //
  270.                         // left-align and vertically center it
  271.                         // give it a weight of 0
  272.                         //
  273.                         GmAddWnd(hGeom, hGroup4, ::GetDlgItem(m_TabPage2.m_hWnd, IDC_INFO_LABEL), GM_LEFT | GM_VCENTER, 0);
  274.                         
  275.                         // add the multiline edit field group
  276.                         //
  277.                         // allow it to grow (in both directions)
  278.                         // give it a weight of 1
  279.                         //
  280.                         GmAddWnd(hGeom, hGroup4, ::GetDlgItem(m_TabPage2.m_hWnd, IDC_INFO), GM_GROW, 1);
  281.                     }
  282.  
  283.                     // add the third tab page
  284.                     //
  285.                     // arrange its direct children vertically
  286.                     // allow it to grow in both directions
  287.                     // give it a weight of 1
  288.                     //
  289.                     hGroup4 = GmAddChildDialog(hGeom, hGroup3, m_TabPage3.m_hWnd, GM_GROW | GM_VERTICAL, 1);
  290.                     if (hGroup4)
  291.                     {
  292.                         // add the generic group for the top two static frame controls
  293.                         //
  294.                         // arrange its direct children horizontally
  295.                         // give it a weight of 1
  296.                         //
  297.                         HGMGROUP hGroup5 = GmAddGroup(hGeom, hGroup4, GM_HORIZONTAL, 1);
  298.                         if (hGroup5)
  299.                         {
  300.                             // add the static frame groups
  301.                             //
  302.                             // allow them to grow (in both directions)
  303.                             // give them a weight of 1
  304.                             //
  305.                             GmAddStaticFrame(hGeom, hGroup5, ::GetDlgItem(m_TabPage3.m_hWnd, IDC_FRAME1), GM_GROW, 1);
  306.                             GmAddStaticFrame(hGeom, hGroup5, ::GetDlgItem(m_TabPage3.m_hWnd, IDC_FRAME2), GM_GROW, 1);
  307.                         }
  308.  
  309.                         // add the bottom static frame group
  310.                         //
  311.                         // allow it to grow (in both directions)
  312.                         // give it a weight of 1
  313.                         //
  314.                         GmAddStaticFrame(hGeom, hGroup4, ::GetDlgItem(m_TabPage3.m_hWnd, IDC_FRAME3), GM_GROW, 1);
  315.                     }
  316.                 }
  317.                 
  318.                 // add the generic group for the buttons
  319.                 //
  320.                 // horizontally center it
  321.                 // arrange its direct children horizontally
  322.                 // give it a weight of 1
  323.                 //
  324.                 hGroup3 = GmAddGroup(hGeom, hGroup2, GM_HORIZONTAL | GM_HCENTER, 0);
  325.                 if (hGroup3)
  326.                 {
  327.                     // add the button groups
  328.                     //
  329.                     // give them a weight of 0
  330.                     //
  331.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_ADD), 0, 0);
  332.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_EDIT), 0, 0);
  333.                     GmAddWnd(hGeom, hGroup3, ::GetDlgItem(m_hWnd, IDC_DELETE), 0, 0);
  334.                 }
  335.             }
  336.         }
  337.     }
  338.     
  339.     // end the definition and start the manager
  340.     //
  341.     VERIFY(GmEndDefinition(hGeom));
  342. }
  343.  
  344. void CSampleView::OnSelchangingTab(NMHDR* /*pNMHDR*/, LRESULT* pResult) 
  345. {
  346.     int iSel = m_TabCtrl.GetCurSel();
  347.  
  348.     switch (iSel)
  349.     {
  350.     case 0:
  351.         m_TabPage1.ShowWindow(SW_HIDE);
  352.         break;
  353.     case 1:
  354.         m_TabPage2.ShowWindow(SW_HIDE);
  355.         break;
  356.     case 2:
  357.         m_TabPage3.ShowWindow(SW_HIDE);
  358.         break;
  359.     }
  360.     
  361.     *pResult = 0;
  362. }
  363.  
  364. void CSampleView::OnSelchangeTab(NMHDR* /*pNMHDR*/, LRESULT* pResult) 
  365. {
  366.     int iSel = m_TabCtrl.GetCurSel();
  367.  
  368.     switch (iSel)
  369.     {
  370.     case 0:
  371.         m_TabPage1.ShowWindow(SW_SHOW);
  372.         break;
  373.     case 1:
  374.         m_TabPage2.ShowWindow(SW_SHOW);
  375.         break;
  376.     case 2:
  377.         m_TabPage3.ShowWindow(SW_SHOW);
  378.         break;
  379.     }
  380.  
  381.     *pResult = 0;
  382. }
  383.